/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;
using SMLib.Base;
using SMLib.Automata.Base;
using System.Collections.Generic;

namespace SMLib.Automata.Kripke
{
	/// <summary>
	/// N-bit kripke
	/// </summary>
	public class NbitKripke : DiGraph<NbitKripke.State, NbitKripke.Transition>
	{
		public class State: IState<NbitKripke.Transition>
		{
			string ID;


			NbitSymbol symb;
			List<Transition> transitions;

			public State(string ID,NbitSymbol symb)
			{
				this.ID=ID;
				transitions=new List<Transition>();
				this.symb=symb;
			}

			public State(string ID)
			{
				this.ID=ID;
				transitions=new List<Transition>();
			}

			public void SetOutput(NbitSymbol bits)
			{
				this.symb = bits;
			}

			public string Identifier
			{
				get{
					return ID;
				}
			}

			public NbitSymbol Output {
				get {
					return symb;
				}
			}

			public List<Transition> Transitions
			{
				get {
					return transitions;
				}
			}

			public override string ToString ()
			{
				return string.Format ("{0}_{1}", Identifier, Output);
			}
		}

		public class Transition
		{
			public Transition(ISymbol symb,State st=null)
			{
				this.label=symb;
				this.dst=st;
			}

			ISymbol label;
			State dst;

			public State Destination {
				get {
					return dst;
				}
			}

			public void SetDestination (NbitKripke.State dstNode)
			{
				this.dst = dstNode;
			}

			/// <summary>
			/// Gets the label.
			/// </summary>
			/// <value>The label.</value>
			public ISymbol Label {
				get {
					return label;
				}
			}

			public override string ToString ()
			{
				return label.ToString();
			}
		}

		Alphabet inputAlphabet;

		public Alphabet InputAlphabet {
			get {
				return inputAlphabet;
			}
		}

		public override State DestinationOf (Transition t)
		{
			return t.Destination;
		}

		public NbitKripke ()
		{
			inputAlphabet = new Alphabet ();
		}
	}
}